package com.sebklebes.radar.converter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ioana Sebestyen
 */
public class ResponseConverter {

	private static final String TAG = ResponseConverter.class.getName();

	public static List<RadarEntity> convertToRadarList(String response) {

		if (response.length() == 0) {
			return new ArrayList<RadarEntity>();
		}

		String[] fields = response.split(";");
		List<RadarEntity> radarEntities = new ArrayList<RadarEntity>();

		for (String field : fields) {
			String[] f = field.split(",");
//			RadarEntity radarEntity = new RadarEntity(Long.parseLong(f[0]), Double.parseDouble(f[1]), Double.parseDouble(f[2]));
			RadarEntity radarEntity = new RadarEntity(Long.parseLong(f[0]), Double.parseDouble(f[1]));
			radarEntities.add(radarEntity);
		}

		return radarEntities;
	}

	public static String convertToString(List<RadarEntity> radars) {
		StringBuilder stringBuilder = new StringBuilder();

		for (RadarEntity radar : radars) {
			stringBuilder.append(radar).append("\n");
		}

		return stringBuilder.toString();
	}

	public static RadarEntity convertToRadar(String response) {
		if (response.length() == 0) {
			return null;
		}

		String[] f = response.split(",");
//		RadarEntity radarEntity = new RadarEntity(Long.parseLong(f[0]), Double.parseDouble(f[1]), Double.parseDouble(f[2]));
		RadarEntity radarEntity = new RadarEntity(Long.parseLong(f[0]), Double.parseDouble(f[1]));
		return radarEntity;
	}
}
